package com.fushenlan.epidemicControl.service.Impl;

import com.alibaba.fastjson.JSON;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.fushenlan.commons.GeneralResponse;
import com.fushenlan.dto.*;
import com.fushenlan.epidemicControl.config.JwtUtil;
import com.fushenlan.epidemicControl.mapper.NucleinDetectionAbnormalPersonnelMapper;
import com.fushenlan.epidemicControl.mapper.NucleinDetectionApplyRecordAbnormalMapper;
import com.fushenlan.epidemicControl.mapper.NucleinDetectionApplyRecordMapper;
import com.fushenlan.epidemicControl.mapper.NucleinDetectionRegisterRecordMapper;
import com.fushenlan.epidemicControl.service.NucleinDetectionApplyRecordService;
import com.fushenlan.po.NucleinDetectionAbnormalPersonnel;
import com.fushenlan.po.NucleinDetectionApplyRecord;
import com.fushenlan.po.NucleinDetectionApplyRecordAbnormal;
import com.fushenlan.po.NucleinDetectionRegisterRecord;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.fushenlan.util.QRCodeGenerator;
import com.google.zxing.WriterException;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.codec.binary.Base64;
import org.apache.poi.ss.formula.functions.T;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.IOException;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

/**
* @author Administrator
* @description 针对表【nuclein_detection_apply_record(核酸检测申请记录表)】的数据库操作Service实现
* @createDate 2022-04-20 22:33:26
*/
@Slf4j
@Service
public class NucleinDetectionApplyRecordServiceImpl extends ServiceImpl<NucleinDetectionApplyRecordMapper, NucleinDetectionApplyRecord>
implements NucleinDetectionApplyRecordService{

    @Autowired
    private NucleinDetectionApplyRecordMapper nucleinDetectionApplyRecordMapper;

    @Autowired
    private NucleinDetectionRegisterRecordMapper nucleinDetectionRegisterRecordMapper;

    @Autowired
    private NucleinDetectionAbnormalPersonnelMapper nucleinDetectionAbnormalPersonnelMapper;

    @Autowired
    private NucleinDetectionApplyRecordAbnormalMapper nucleinDetectionApplyRecordAbnormalMapper;

    /**
     * 登录人居民表id
     */
    private static final String IN_HABITANT_ID = "userId";  //登录人居民表id

    @Override
    public GeneralResponse<PersonalDetectionRespDTO> personalDetection() {
        //获取当前登录人
        Long userId=Long.valueOf(JwtUtil.getUserInfo(IN_HABITANT_ID)).longValue();
        log.info("个人页面核酸检测记录查询 Request userId->{}",userId);
        List<PersonalDetectionDTO> personalDetectionDTORecords=nucleinDetectionApplyRecordMapper.selectDetectionList(userId);
        PersonalDetectionRespDTO personalDetectionRespDTO=new PersonalDetectionRespDTO();
        personalDetectionRespDTO.setPersonalDetectionNotice(personalDetectionDTORecords.stream().filter(personalDetectionDTO ->  personalDetectionDTO.getType()==1).collect(Collectors.toList()));
        personalDetectionRespDTO.setPersonalDetectionRegister(personalDetectionDTORecords.stream().filter(personalDetectionDTO ->  personalDetectionDTO.getType()==3).collect(Collectors.toList()));
        personalDetectionRespDTO.setPersonalDetectionResult(personalDetectionDTORecords.stream().filter(personalDetectionDTO ->  personalDetectionDTO.getType()==2).collect(Collectors.toList()));
        log.info("个人页面核酸检测记录查询 Response personalDetectionRespDTO->{}",personalDetectionRespDTO);
        return GeneralResponse.success(personalDetectionRespDTO);
    }

    @Override
    public GeneralResponse<List<PersonalDetectionResultRespDTO>> personalDetectionResult(Long recordId) {
        //获取当前登录人
        Long userId=Long.valueOf(JwtUtil.getUserInfo(IN_HABITANT_ID)).longValue();
        log.info("个人页面核酸检测查询结果 Request userId->{} recordId->{}",userId,recordId);
        List<PersonalDetectionResultRespDTO> personalDetectionResultRespDTOS=nucleinDetectionApplyRecordMapper.personalDetectionResult(userId,recordId);
        log.info("个人页面核酸检测查询结果 Response personalDetectionResultRespDTOS->{}",personalDetectionResultRespDTOS);
        return GeneralResponse.success(personalDetectionResultRespDTOS);
    }

    @Override
    @Transactional(rollbackFor = Exception.class)
    public GeneralResponse personalDetectionResultCommit(List<PersonalDetectionResultRespDTO> personalDetectionResultRespDTOS) throws Exception {
        log.info("个人页面核酸检测提交结果 Request personalDetectionResultRespDTOS->{}",personalDetectionResultRespDTOS);
        if (personalDetectionResultRespDTOS==null||personalDetectionResultRespDTOS.size()==0){
            return GeneralResponse.success("请登记结果");
        }
        for(PersonalDetectionResultRespDTO personalDetectionResultRespDTO:personalDetectionResultRespDTOS){
            if(personalDetectionResultRespDTO.getType()==2){ //结果登记
                if (personalDetectionResultRespDTO.getDetectionResult()==null){
                    continue;
                }
            NucleinDetectionRegisterRecord nucleinDetectionRegisterRecord=
                    nucleinDetectionRegisterRecordMapper.selectOne(new LambdaQueryWrapper<NucleinDetectionRegisterRecord>()
                    .eq(NucleinDetectionRegisterRecord::getUserId,personalDetectionResultRespDTO.getId())
                    .eq(NucleinDetectionRegisterRecord::getIfRegister,0)  //未登记
                    .eq(NucleinDetectionRegisterRecord::getIfDetection,1) //已检测
                    .eq(NucleinDetectionRegisterRecord::getDetectionApplyId,personalDetectionResultRespDTO.getRecordId()));
            if (nucleinDetectionRegisterRecord!=null){
                //更新核酸检测登记表
                nucleinDetectionRegisterRecord.setDetectionResult(personalDetectionResultRespDTO.getDetectionResult());
                nucleinDetectionRegisterRecord.setIfRegister(1);
                nucleinDetectionRegisterRecord.setUpdateTime(LocalDateTime.now());
                nucleinDetectionRegisterRecord.setUpdateUser("system");
                nucleinDetectionRegisterRecordMapper.updateById(nucleinDetectionRegisterRecord);
                //判断是否为阳性
                if (personalDetectionResultRespDTO.getDetectionResult()==1){
                    //查询异常结果表里是否已存在
                    NucleinDetectionAbnormalPersonnel nucleinDetectionAbnormalPersonnel=
                            nucleinDetectionAbnormalPersonnelMapper.selectOne(new LambdaQueryWrapper<NucleinDetectionAbnormalPersonnel>()
                                    .eq(NucleinDetectionAbnormalPersonnel::getUserId,personalDetectionResultRespDTO.getId())
                                    .eq(NucleinDetectionAbnormalPersonnel::getHealthStatus,personalDetectionResultRespDTO.getDetectionResult()));
                    if(nucleinDetectionAbnormalPersonnel==null){
                        //插入核酸异常表
                        nucleinDetectionAbnormalPersonnel=new NucleinDetectionAbnormalPersonnel();
                        nucleinDetectionAbnormalPersonnel.setUserId(personalDetectionResultRespDTO.getId());
                        nucleinDetectionAbnormalPersonnel.setHealthStatus(personalDetectionResultRespDTO.getDetectionResult());
                        nucleinDetectionAbnormalPersonnel.setUserStatus(1);//未转运
                        nucleinDetectionAbnormalPersonnel.setCreateTime(LocalDateTime.now());
                        nucleinDetectionAbnormalPersonnel.setCreateUser("system");
                        nucleinDetectionAbnormalPersonnel.setUpdateTime(LocalDateTime.now());
                        nucleinDetectionAbnormalPersonnel.setUpdateUser("system");
                        nucleinDetectionAbnormalPersonnelMapper.insert(nucleinDetectionAbnormalPersonnel);
                    }
                    NucleinDetectionApplyRecordAbnormal nucleinDetectionApplyRecordAbnormalA=
                            nucleinDetectionApplyRecordAbnormalMapper.selectOne(new LambdaQueryWrapper<NucleinDetectionApplyRecordAbnormal>()
                                    .eq(NucleinDetectionApplyRecordAbnormal::getDetectionApplyId,personalDetectionResultRespDTO.getRecordId())
                                    .eq(NucleinDetectionApplyRecordAbnormal::getAbnormalPersonnelId,nucleinDetectionAbnormalPersonnel.getId()));
                    if (nucleinDetectionApplyRecordAbnormalA==null) {
                        //插入核酸记录核酸异常快照表
                        NucleinDetectionApplyRecordAbnormal nucleinDetectionApplyRecordAbnormal = new NucleinDetectionApplyRecordAbnormal();
                        nucleinDetectionApplyRecordAbnormal.setDetectionApplyId(personalDetectionResultRespDTO.getRecordId());
                        nucleinDetectionApplyRecordAbnormal.setAbnormalPersonnelId(nucleinDetectionAbnormalPersonnel.getId());
                        nucleinDetectionApplyRecordAbnormal.setCreateTime(LocalDateTime.now());
                        nucleinDetectionApplyRecordAbnormal.setCreateUser("system");
                        nucleinDetectionApplyRecordAbnormal.setUpdateTime(LocalDateTime.now());
                        nucleinDetectionApplyRecordAbnormal.setUpdateUser("system");
                        nucleinDetectionApplyRecordAbnormalMapper.insert(nucleinDetectionApplyRecordAbnormal);
                    }
                }
            }else{
                throw new Exception("当前人员已登记或未检测");
            }

            } else if (personalDetectionResultRespDTO.getType()==1){//检测等级
                List<NucleinDetectionRegisterRecord> nucleinDetectionRegisterRecordList=
                        nucleinDetectionRegisterRecordMapper.selectList(new LambdaQueryWrapper<NucleinDetectionRegisterRecord>()
                                .eq(NucleinDetectionRegisterRecord::getUserId,personalDetectionResultRespDTO.getId())
                                .eq(NucleinDetectionRegisterRecord::getDetectionApplyId,personalDetectionResultRespDTO.getRecordId()));
                if (nucleinDetectionRegisterRecordList==null||nucleinDetectionRegisterRecordList.size()==0){
                    //插入核酸检测表 标注检测状态
                    NucleinDetectionRegisterRecord nucleinDetectionRegisterRecord=new NucleinDetectionRegisterRecord();
                    nucleinDetectionRegisterRecord.setUserId(personalDetectionResultRespDTO.getId());
                    nucleinDetectionRegisterRecord.setDetectionApplyId(personalDetectionResultRespDTO.getRecordId());
                    nucleinDetectionRegisterRecord.setIfDetection(personalDetectionResultRespDTO.getIfDetection());
                    nucleinDetectionRegisterRecord.setIfRegister(0);
                    nucleinDetectionRegisterRecord.setCreateTime(LocalDateTime.now());
                    nucleinDetectionRegisterRecord.setCreateUser("system");
                    nucleinDetectionRegisterRecord.setUpdateTime(LocalDateTime.now());
                    nucleinDetectionRegisterRecord.setUpdateUser("system");
                    nucleinDetectionRegisterRecordMapper.insert(nucleinDetectionRegisterRecord);
                }else{
                    NucleinDetectionRegisterRecord nucleinDetectionRegisterRecord=nucleinDetectionRegisterRecordList.get(0);
                    nucleinDetectionRegisterRecord.setIfDetection(1);
                    nucleinDetectionRegisterRecordMapper.updateById(nucleinDetectionRegisterRecord);
                }
            }
        }
        return GeneralResponse.success();
    }

    /**
     * 居委会核酸检测记录统计主页
     * @param
     * @return
     */
    @Override
    public GeneralResponse<NeighborhoodDetectionCensusRespDTO> neighborhoodDetectionCensus() {
        //获取当前登录人
        Long userId=Long.valueOf(JwtUtil.getUserInfo(IN_HABITANT_ID)).longValue();
        log.info("居委会核酸检测记录统计主页 Request userId->{}",userId);
        //查询该居委下所有累计未转运 累计已转运   累计阳性
        NeighborhoodDetectionCensusRespDTO neighborhoodDetectionCensusRespDTO=nucleinDetectionApplyRecordMapper.selectDetectionNum(userId,null);
        if (neighborhoodDetectionCensusRespDTO==null){
            neighborhoodDetectionCensusRespDTO=new NeighborhoodDetectionCensusRespDTO();
        }
        neighborhoodDetectionCensusRespDTO.setCutOffTime(LocalDateTime.now().format(DateTimeFormatter.ofPattern("YYYY-MM-dd")));
        //查出当前人所属的居委会id以及下面所有的小区     neighborhood_member  居委会人员表    building_info 小区表
        List<DetectionDayDTO> detectionDayList=nucleinDetectionApplyRecordMapper.selectCommunityDetectionInfo(userId);
        detectionDayList.forEach(detectionDayDTO -> {
            //查出当前小区当次核酸检测结果未登记人数 登记未检测人数 结果为阳性人数 对应数据
            Map<String,Long> detectionNum=nucleinDetectionApplyRecordMapper.selectNotRegisterNum(detectionDayDTO.getDetectionId(),detectionDayDTO.getCommunityId());
            //检测结果未登记人数
            detectionDayDTO.setNotRegisterNum( detectionNum.get("not_register_num"));
            //登记未检测人数
            detectionDayDTO.setNotDetectionNum( detectionNum.get("not_detection_num"));
            //检测结果为阳性人数
            detectionDayDTO.setYangNum(detectionNum.get("yang_num"));
        });
        neighborhoodDetectionCensusRespDTO.setDetectionDayList(detectionDayList);
        log.info("居委会核酸检测记录统计主页 Response neighborhoodDetectionCensusRespDTO->{}",neighborhoodDetectionCensusRespDTO);
        return GeneralResponse.success(neighborhoodDetectionCensusRespDTO);
    }


    /**
     * 未转运信息汇总人员查找
     * @param name
     * @param community
     * @return
     */
    @Override
    public GeneralResponse<List<PersonalInfoRespDTO>> notTransportCensus(String name, Long community,Integer status) {
        //获取当前登录人
        Long userId=Long.valueOf(JwtUtil.getUserInfo(IN_HABITANT_ID)).longValue();
        log.info("未转运信息汇总人员查找 Request userId->{}",userId);
        List<PersonalInfoRespDTO> personalInfoRespDTOS=nucleinDetectionApplyRecordMapper.notTransportCensus(userId,name,community,status);
        log.info("未转运信息汇总人员查找 Response personalInfoRespDTOS->{}",personalInfoRespDTOS);
        return GeneralResponse.success(personalInfoRespDTOS);
    }

    @Override
    public GeneralResponse<NeighborhoodDetectionCensusRespDTO> communityDetectionCensus(Long community) {
        //获取当前登录人
        Long userId=Long.valueOf(JwtUtil.getUserInfo(IN_HABITANT_ID)).longValue();
        log.info("小区核酸检测记录统计主页 Request userId->{},community->{}",userId,community);
        //查询该小区下所有累计未转运 累计已转运   累计阳性
        NeighborhoodDetectionCensusRespDTO neighborhoodDetectionCensusRespDTO=nucleinDetectionApplyRecordMapper.selectDetectionNum(userId,community);
        if (neighborhoodDetectionCensusRespDTO==null){
            neighborhoodDetectionCensusRespDTO=new NeighborhoodDetectionCensusRespDTO();
        }
        neighborhoodDetectionCensusRespDTO.setCutOffTime(LocalDateTime.now().format(DateTimeFormatter.ofPattern("YYYY-MM-dd")));

        //查出该小区所有的核酸检测记录id
        List<DetectionDayDTO> detectionDayList=nucleinDetectionApplyRecordMapper.selectCommunityDetectionAllInfo(community);
        detectionDayList.forEach(detectionDayDTO -> {
            //查出当前小区当次核酸检测结果未登记人数 登记未检测人数 结果为阳性人数 对应数据
            Map<String,Long> detectionNum=nucleinDetectionApplyRecordMapper.selectNotRegisterNum(detectionDayDTO.getDetectionId(),community);
            //检测结果未登记人数
            detectionDayDTO.setNotRegisterNum(detectionNum.get("not_register_num"));
            //登记未检测人数
            detectionDayDTO.setNotDetectionNum(detectionNum.get("not_detection_num"));
            //检测结果为阳性人数
            detectionDayDTO.setYangNum(detectionNum.get("yang_num"));
        });
        neighborhoodDetectionCensusRespDTO.setDetectionDayList(detectionDayList);
        log.info("小区核酸检测记录统计主页 Response neighborhoodDetectionCensusRespDTO->{}",neighborhoodDetectionCensusRespDTO);
        return GeneralResponse.success(neighborhoodDetectionCensusRespDTO);
    }

    /**
     * 小区核酸检测记录统计详情
     * @param detectionId  核酸检测记录id
     * @param community  小区
     * @param name  姓名搜索
     * @param status  1-未检测 2-结果未登记 3-已检测  4-结果已登记 5-检测阳性 6-未转运 7-已转运 8-已治愈
     * @param pageSize  每页显示条数
     * @param pagerNum  当前页
     * @return
     */
    @Override
    public GeneralResponse<IPage<PersonalInfoRespDTO>> communityDetectionInfo(Long detectionId, Long community, String name, Integer status, Integer pageSize, Integer pagerNum) {
        log.info("小区核酸检测记录统计详情 Request detectionId->{},community->{},name->{},status->{}",detectionId,community,name,status);

        IPage<PersonalInfoRespDTO> personalInfoRespDTOPage=null;
        switch (status){
            //未检测人员查询
            case 1:
                personalInfoRespDTOPage=nucleinDetectionApplyRecordMapper.notDetectionPeople(new Page<>(pagerNum,pageSize),detectionId,community,name);
                break;
            //结果未登记人员 已登记
            case 2:
            case 4:
                personalInfoRespDTOPage=nucleinDetectionApplyRecordMapper.registerPeople(new Page<>(pagerNum,pageSize),detectionId,community,name,status);
                break;
            //已检测人员
            case 3:
                personalInfoRespDTOPage=nucleinDetectionApplyRecordMapper.detectionPeople(new Page<>(pagerNum,pageSize),detectionId,community,name);
                break;
            //检测阳性 未转运 已转运 已治愈
            case 5 :
            case 6 :
            case 7 :
            case 8 :
                personalInfoRespDTOPage=nucleinDetectionApplyRecordMapper.yangPeople(new Page<>(pagerNum,pageSize),detectionId,community,name,status);
                break;
        }

        log.info("小区核酸检测记录统计详情 Response personalInfoRespDTOPage->{}",personalInfoRespDTOPage);
        return GeneralResponse.success(personalInfoRespDTOPage);
    }

    /**
     * 转运治愈登记
     */
    @Override
    @Transactional(rollbackFor = Exception.class)
    public GeneralResponse personalStatusCommit(PersonalStatusCommitReqDTO personalStatusCommitReqDTO) {
        log.info("转运治愈登记 Request personalStatusCommitReqDTO->{}",personalStatusCommitReqDTO);

        NucleinDetectionAbnormalPersonnel nucleinDetectionAbnormalPersonnel=nucleinDetectionAbnormalPersonnelMapper.selectOne(new LambdaQueryWrapper<NucleinDetectionAbnormalPersonnel>()
                .eq(NucleinDetectionAbnormalPersonnel::getUserId,personalStatusCommitReqDTO.getId())
                .eq(NucleinDetectionAbnormalPersonnel::getHealthStatus,1));
        if(nucleinDetectionAbnormalPersonnel==null){
            return GeneralResponse.success("当前人员健康状态有误");
        }
        if (personalStatusCommitReqDTO.getStatus()==2){
            //转运
            nucleinDetectionAbnormalPersonnel.setUserStatus(personalStatusCommitReqDTO.getStatus());
            nucleinDetectionAbnormalPersonnel.setTransportTime(personalStatusCommitReqDTO.getTransportTime());
            nucleinDetectionAbnormalPersonnel.setTransportPlace(personalStatusCommitReqDTO.getTransportPlace());
        }
        if (personalStatusCommitReqDTO.getStatus()==3){
            //治愈
            nucleinDetectionAbnormalPersonnel.setUserStatus(personalStatusCommitReqDTO.getStatus());
            nucleinDetectionAbnormalPersonnel.setHealthStatus(2);
            nucleinDetectionAbnormalPersonnel.setHomeTime(personalStatusCommitReqDTO.getHomeTime());
            nucleinDetectionAbnormalPersonnel.setRemarks(personalStatusCommitReqDTO.getRemarks());
        }
        nucleinDetectionAbnormalPersonnelMapper.updateById(nucleinDetectionAbnormalPersonnel);
        return GeneralResponse.success();
    }

    /**
     * 密接查询
     * @param userId  用户id
     * @return
     */
    @Override
    public GeneralResponse<List<PersonalInfoRespDTO>> closeContactInfo(Long userId,Long detectionId) {
        log.info("密接查询 Request userId->{},detectionId->{}",userId,detectionId);
        List<PersonalInfoRespDTO> personalInfoRespDTOS=nucleinDetectionApplyRecordMapper.closeContactInfo(userId,detectionId);
        log.info("密接查询 Response personalInfoRespDTOS->{}",personalInfoRespDTOS);
        return GeneralResponse.success(personalInfoRespDTOS);
    }

    @Override
    public GeneralResponse<List<CommunityDTO>> getCommunityList(Long userId) {
        //获取当前登录人
        userId=Long.valueOf(JwtUtil.getUserInfo(IN_HABITANT_ID)).longValue();
        log.info("居委下的下去查询 Request userId->{}",userId);
        List<CommunityDTO> communityDTOList=nucleinDetectionApplyRecordMapper.getCommunityList(userId);
        CommunityDTO communityDTO=new CommunityDTO();
        communityDTO.setCommunityName("全部小区");
        communityDTOList.add(0,communityDTO);
        log.info("居委下的下去查询 Response communityDTOList->{}",communityDTOList);
        return GeneralResponse.success(communityDTOList);
    }

    @Override
    public GeneralResponse<String> getQRCode(Long detectionId) throws IOException, WriterException {
        //判断当前核酸检测记录是否在该居委下
        Integer ifTrue=nucleinDetectionApplyRecordMapper.getIfTrue(detectionId,Long.valueOf(JwtUtil.getUserInfo(IN_HABITANT_ID)).longValue());
        if(ifTrue==0){
            return GeneralResponse.fail("-1","没有权限生成二维码","");
        }
        QRCodeDTO qrCodeDTO=new QRCodeDTO();
        qrCodeDTO.setKey("fslnb");
        qrCodeDTO.setValue(detectionId);
        String str= JSON.toJSONString(qrCodeDTO);
        byte[] data = null;
        ByteArrayOutputStream stream=new ByteArrayOutputStream ();
        QRCodeGenerator.generateQRCodeImage(stream,str);
        //生成base64对应二维码
        data = stream.toByteArray();
        stream.close();
        return GeneralResponse.success(new String(Base64.encodeBase64(data)));
    }

    @Override
    @Transactional(rollbackFor = Exception.class)
    public GeneralResponse personalDetectionCommit(List<PersonalDetectionResultRespDTO> personalDetectionResultRespDTOS) {
        log.info("个人页面核酸检测提交检测状态 Request personalDetectionResultRespDTOS->{}",personalDetectionResultRespDTOS);
        if (personalDetectionResultRespDTOS==null||personalDetectionResultRespDTOS.size()==0){
            return GeneralResponse.success("请登记结果");
        }
        for(PersonalDetectionResultRespDTO personalDetectionResultRespDTO:personalDetectionResultRespDTOS){
            if (personalDetectionResultRespDTO.getType()==1){//检测登记
                personalDetectionResultRespDTO.setId(Long.valueOf(JwtUtil.getUserInfo(IN_HABITANT_ID)).longValue());
                List<NucleinDetectionRegisterRecord> nucleinDetectionRegisterRecordList=
                        nucleinDetectionRegisterRecordMapper.selectList(new LambdaQueryWrapper<NucleinDetectionRegisterRecord>()
                                .eq(NucleinDetectionRegisterRecord::getUserId,personalDetectionResultRespDTO.getId())
                                .eq(NucleinDetectionRegisterRecord::getDetectionApplyId,personalDetectionResultRespDTO.getRecordId()));
                if (nucleinDetectionRegisterRecordList==null||nucleinDetectionRegisterRecordList.size()==0){
                    return GeneralResponse.fail("-1","不在检测范围内请联系居委管理员进行操作","");
                }else{
                    NucleinDetectionRegisterRecord nucleinDetectionRegisterRecord=nucleinDetectionRegisterRecordList.get(0);
                    nucleinDetectionRegisterRecord.setIfDetection(1);
                    nucleinDetectionRegisterRecordMapper.updateById(nucleinDetectionRegisterRecord);
                }
            }
        }
        return GeneralResponse.success();
    }
}
